package com.kgc.chapter01.vars
import scala.util.Try
object Test {
  def main(augrs : Array[String]) : Unit ={
          /*cvt_int("abc") match{
            case Some(v) => println("That value is %s".format(v))
            case None => println("Convert failed")
          }*/


       //getOrElse就是判断，如果成立就输出，不成立返回0
       println(cvt_int("aaa").getOrElse(0))
  }

  def cvt_int (x : Any): Option[Int] ={
    try {
      Some(x.toString().toInt)
    }catch {
      case e : java.lang.Exception => None
    }
  }

}
